﻿namespace Command_Pattern
{
    public class Waiter
    {
        private IList<Command> orders = new List<Command>();


        public void SetOrder(Command command)
        {
            //检查食物剩余数量
            int count = Inventory.RemainingInventory(command.name);
            if (count > command.count)
            {
                if(Inventory.ReduceInventory(new Food(command.name, command.count)))
                {
                    orders.Add(command);
                    Console.WriteLine($"增加订单：{command.name} 数量：{command.count} 时间：{DateTime.Now.ToString()}");
                }
            }
            else
            {
                if(count == 0)
                {
                    Console.WriteLine($"服务员：{command.name}没有了，请点别的烧烤!");
                }
                else
                {
                    Console.WriteLine($"服务员：{command.name}还剩{count}串，不够{command.count}串了!");
                }
            }
        }

        public void CancelOrder(Command command)
        {
            orders.Remove(command);
            Inventory.IncreaseInventory(new Food(command.name, command.count));
        }
        public void Notify()
        {
            foreach (Command command in orders)
            {
                command.Execute();
                orders.Remove(command);
            }
        }
    }
}
